/*
 * Grid.fx
 *
 * Created on 20-mars-2010, 18:35:10
 */

package nc.jfxsudoku.customnode;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.shape.Line;
import nc.jfxsudoku.customnode.Cell;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.HBox;
import javafx.ext.swing.SwingButton;
import javafx.scene.control.Button;

/**
 * @author ncolboc
 */

def GRID_STROKE_WIDTH = 10;

public class Grid extends CustomNode
{
    function createCells():Node
    {
        var grid = Group
        {
            translateX:GRID_STROKE_WIDTH/2
            translateY:GRID_STROKE_WIDTH/2 + 40
        }

        for (i in [0..8])
        {
            for (j in [0..8])
            {
                insert Cell
                {
                    row:i
                    column:j
                    value:0
                } into grid.content;
            }
        }

        return grid;
    }

    function createGrid():Node
    {
        var grid = Group
        {
            translateY:40
            content:
            [
                Rectangle
                {
                    x:0
                    y:0
                    width:30*9 + GRID_STROKE_WIDTH
                    height:30*9 + GRID_STROKE_WIDTH
                    stroke:Color.GRAY
                    strokeWidth:GRID_STROKE_WIDTH
                    fill:Color.WHITE
                }
            ]
        }

        for (i in [1..2])
        {
            insert Line
            {
                startX:0
                startY:(30*3)*i + GRID_STROKE_WIDTH/2
                endX:30*9 + GRID_STROKE_WIDTH
                endY:(30*3)*i +  GRID_STROKE_WIDTH/2
                stroke:Color.GRAY
                strokeWidth:3
            } into grid.content;
        }

        for (i in [1..2])
        {
            insert Line
            {
                startY:0
                startX:(30*3)*i + GRID_STROKE_WIDTH/2
                endY:30*9 + GRID_STROKE_WIDTH
                endX:(30*3)*i +  GRID_STROKE_WIDTH/2
                stroke:Color.GRAY
                strokeWidth:3
            } into grid.content;
        }

        return grid;
    }

    function createButtons():Node
    {
        return HBox
        {
            content:
            [
                Button
                {
                    text: "New"
                    action: function()
                    {
                    }
                }
            ]
        }

    }


    override protected function create():Node
    {
        return Group
        {
            content:[createButtons(),createGrid(), createCells()]
        }        
    }


}
